package com.digital.herbarium.Controller;

import com.digital.herbarium.annotation.CheckToken;
import com.digital.herbarium.Entity.Popular;
import com.digital.herbarium.Entity.ResponseResult;
import com.digital.herbarium.annotation.Log;
import com.digital.herbarium.service.PopularService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/popluar")
public class PopularContorller {

    @Autowired
    PopularService popularService;

    @GetMapping("getPopularInfo")
    @Log("popluar")
    public ResponseResult getPopularInfo(Popular popular,
                                         @RequestParam(value = "pageSize",defaultValue = "10",required = false) int pageSize,
                                         @RequestParam(value = "pageNum",defaultValue = "0",required = false) int pageNum){
        popular.setFront(-1);
        return ResponseResult.SUCCESS().setData( popularService.getPopularInfo(popular, pageSize,  pageNum));
    }

    @GetMapping("getManagerPopularInfo")
    @CheckToken()
    @Log("popluar")
    public ResponseResult getManagerPopularInfo(Popular popular,
                                         @RequestParam(value = "pageSize",defaultValue = "10",required = false) int pageSize,
                                         @RequestParam(value = "pageNum",defaultValue = "0",required = false) int pageNum){
        return ResponseResult.SUCCESS().setData( popularService.getPopularInfo(popular, pageSize,  pageNum));

    }


    @PostMapping("addPopular")
    @CheckToken()
    public  ResponseResult addPopular(Popular popular){
        Integer id = popularService.addPopular(popular);
        return ResponseResult.SUCCESS().setData(id);
    }

    @PostMapping("editPopular")
    @CheckToken()
    public ResponseResult editPopular(Popular popular){
        popularService.editPopular(popular);
        return  ResponseResult.SUCCESS().setData("更新成功");
    }

    @GetMapping("delPopular")
    @CheckToken()
    public ResponseResult delPopular(String id){
        popularService.delPopular(id);
        return  ResponseResult.SUCCESS().setData("删除成功");
    }


    @GetMapping("offPopular")
    @CheckToken()
    public ResponseResult offPopular(String id,Integer state){
        popularService.offPopular(id,state);
        return  ResponseResult.SUCCESS().setData("更新成功");
    }

}
